import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;

/**
 * Anagrams 
 */

public class Anagrams
{
	public static void main(String[] args)
	{
		try
		{
			Scanner inFile = new Scanner(new File("unixdict.txt"));
			Map<String, ArrayList<String> > wordSet = new HashMap<String, ArrayList<String> >();
			int count = 0;
			while (inFile.hasNextLine())
			{
				String key = inFile.nextLine();
				char[] keyStr = key.toCharArray();
				Arrays.sort(keyStr);
				String sortKey =  String.copyValueOf(keyStr);
				if (!wordSet.containsKey(sortKey))
				{
					wordSet.put(sortKey, new ArrayList<String>());
				}
				wordSet.get(sortKey).add(key);
				count = Math.max(count, wordSet.get(sortKey).size());
			}
			
			// Output max size anagrams word list
			Set<String> keys = wordSet.keySet();
			for (String key : keys)
			{
				ArrayList<String> outList = wordSet.get(key);
				if (outList.size() == count)
				{
					System.out.println(outList);
				}
			}
			inFile.close();	
		}
		catch (IOException exception)
		{
			exception.printStackTrace();			
		}	
	}
}

/*
import java.net.*;
import java.io.*;
import java.util.*;
 
public class WordsOfEqChars {
    public static void main(String[] args) throws IOException {
        URL url = new URL("http://www.puzzlers.org/pub/wordlists/unixdict.txt");
        InputStreamReader isr = new InputStreamReader(url.openStream());
        BufferedReader reader = new BufferedReader(isr);
 
        Map<String, Collection<String>> anagrams = new HashMap<String, Collection<String>>();
        String word;
        int count = 0;
        while ((word = reader.readLine()) != null) {
            char[] chars = word.toCharArray();
            Arrays.sort(chars);
            String key = new String(chars);
            if (!anagrams.containsKey(key))
                anagrams.put(key, new ArrayList<String>());
            anagrams.get(key).add(word);
            count = Math.max(count, anagrams.get(key).size());
        }
 
        reader.close();
 
        for (Collection<String> ana : anagrams.values())
            if (ana.size() >= count)
                System.out.println(ana);
    }   
}
*/